package com.qdxwx.web.controller.ajax;

import com.qdxwx.common.json.AjaxResult;
import com.qdxwx.common.utils.TKConvert;
import com.qdxwx.data.service.course.CourseNodeService;
import com.qdxwx.data.service.course.CourseStudyHistoryService;
import com.qdxwx.models.course.CourseNode;
import com.qdxwx.web.controller.BaseController;
import com.qdxwx.web.utils.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
/*
*
* 沒有用上的
*
* */
@Controller
@RequestMapping("/ajax/course/node")
public class AjaxCourseNodeController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(AjaxCourseNodeController.class);

	@Autowired
	private CourseNodeService courseNodeService;
	@Autowired
	private CourseStudyHistoryService courseStudyHistoryService;

	@GetMapping("/list.json")
	@ResponseBody
	public AjaxResult list(HttpServletRequest request) {
		long userId = LoginUser.getUserId(request);

		int courseId = TKConvert.toInteger(request.getParameter("courseId"));

		if (courseId < 1) {
			return AjaxResult.error("参数异常");
		}

		List<CourseNode> nodeList = courseNodeService.getTreeByCourseId(courseId);
		courseStudyHistoryService.setIsStudy(nodeList, userId, courseId);

		return AjaxResult.success(nodeList);
	}
}